// pages/user/index.js
import BB from '../../hq-app/hqApp';
const App = getApp();
Component({
    behaviors: [BB],

    /**
     * 页面的初始数据
     */
    data: {
        islogin: 0,
        iconList: [{
            icon: 'picfill',
            color: 'red',
            badge: 0,
            name: '轮播管理',
            url: '/pages/agent/banner'
        }, {
            icon: 'friendfavor',
            color: 'orange',
            badge: 0,
            name: '艺人管理',
            url: '/pages/agent/actor'
        }, {
            icon: 'noticefill',
            color: 'yellow',
            badge: 0,
            name: '通告管理',
            url: '/pages/agent/notice'
        }],
    },

    /**
     * 组件的方法列表
     */
    methods: {
        
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {
            
        },
        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {
            var _this = this;
            //获取数据
            _this.getData();
        },
        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function () {
            var _this = this;
            wx.showToast({
                title: '正在刷新数据...',
                icon: 'loading',
                duration: 1500
            });
            _this.onShow();
            wx.stopPullDownRefresh();//停止刷新操作
        },
        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function () {
            
        },
        /**
         * 获取参数详情
         */
        getData() {
            let _this = this;
            App._get('user/index', {
            }, function (result) {
                _this.setData(result.data);
                console.log(result);
            });
        },
        //获取微信资料
        bindGetUserInfo(e) {
            let _this = this;
            App._get('user/update_userinfo', {
                avatar: e.detail.userInfo.avatarUrl,
                nickname: e.detail.userInfo.nickName,
                country: e.detail.userInfo.country,
                province: e.detail.userInfo.province,
                city: e.detail.userInfo.city,
                gender: e.detail.userInfo.gender,
                user_id: wx.getStorageSync('user_id')
            }, function (result) {
                App.showSuccess(result.msg);
                _this.getData();
            });
        },
        /** 
         * 更新城市
         */
        update_city: function (e) {
            let _this = this;
            // 提交到后端
            App._get('user/update_city', '', function (result) {
                App.showSuccess(result.msg, function () {
                    _this.getData();
                });
            }, false, function () {
                // 解除禁用
                _this.setData({
                    disabled: false
                });
            });

        },
        //退出登录
        logout() {
            let _this = this;
            wx.removeStorageSync('user_id');
            wx.removeStorageSync('sessionid');
            wx.reLaunch({
                url: '/pages/user/index',
            });
        },
        

    }

})